﻿using System.Collections.Generic;
using Sliver.Roadnet.RawInfo;
using UnityEngine;

namespace Sliver.Roadnet.Components
{
    public class RoadLinkEntity : MonoBehaviour
    {
        public RawRoadLinkInfo RawInfo { get; protected set; }

        [HideInInspector]
        public List<LanelinkEntity> lanelinks = new List<LanelinkEntity>();

        public void Setup(RawRoadLinkInfo info)
        {
            RawInfo = info;
            gameObject.name = $"road_link_{info.startRoad}_{info.endRoad}";

            for (int i = 0; i < info.laneLinks.Count; i++)
            {
                RawLanelinkInfo lanelink = info.laneLinks[i];
                LanelinkEntity entity = Instantiate(RoadnetEntity.LanelinkEntityPrototype, transform);
                entity.gameObject.name = $"lanelink_{i + 1}";
                entity.Setup(entity, lanelink);
            }
        }
    }
}
